<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
          <label class="layui-form-label" >逝者姓名</label>
          <div class="layui-input-inline">
              <el-input v-model="selectData.NameLike" @keydown.enter.native="btnSearch"></el-input>  
          </div>
      </div>
      <div class="layui-inline">
          <label class="layui-form-label" >身份证号</label>
          <div class="layui-input-inline">
              <el-input v-model="selectData.DedcardnoEquals" @keydown.enter.native="btnSearch"></el-input>  
          </div>
      </div>
      <div class="layui-inline">
        <label>安置日期从</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.ArgdateGreaterAndEquals" type="date" placeholder="请选择日期"
            style="width:160px;" /> 到
          <el-date-picker v-date v-model="selectData.ArgdateLessAndEquals" type="date" placeholder="请选择日期"
            style="width:160px;" />
        </div>
      </div>
      <div class="layui-inline" style="margin-left:20px">
        <label>安置方式</label>
        <div class="layui-input-inline">
        <el-select v-model="selectData.ArgwayEquals" placeholder="请选择安置方式">
            <el-option :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue" v-for="item in anzhiOptipns"></el-option>
        </el-select>
        <label>统计地址</label>
        <el-select v-model="selectData.DedaddidEquals" placeholder="请选择统计地址">
            <el-option :key="item.ADDID" :label="item.ADDNAME" :value="item.ADDID" v-for="item in tongjiOptions"></el-option>
        </el-select>
        </div>
      </div>
      <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading" style="margin-left:20px;">搜索
      </el-button>
      <el-button @click="btnRepeat">重置</el-button>
    </div>

    <!-- 功能列表 -->
    <div style="margin-top:10px;">
      <ul class="toolList">
        <li>
          <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button>
        </li>
        <!-- <li><el-button type="primary" @click="exportExcel">导出Excel</el-button></li> -->
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon"
          @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <!-- 数据列表 -->
    <dataTable :headList="headList" :dataList="dataList" :hiddenColumn="false" :hiddenPageOrder="false" :isIndex='true'
      :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <printmodal ref="printPdf"></printmodal>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/styles/common.scss";

  .el-button+.el-button {
    margin-left: 0;
  }

  .btnCenter {
    text-align: center;
  }

</style>
<script>
  import sweetModal from "@/components/sweetModal";
  import dataTable from "@/components/Table/DataTable";
  import printmodal from "@/components/Pdf/Print";
  import apiBase from "@/api/apiBase.js";
  import {
    formatDate,
    timeStringToDate
  } from "@/utils/date.js";
  import {
    manage
  } from "@/mixins/managePage.js";
  export default {
    name: "assUse",
    mixins: [manage],
    data() {
      return {
        pageWidth: 1200,
        selectData: {
          ArgdateGreaterAndEquals: null,
          ArgdateLessAndEquals: null,
          ArgwayEquals: null,
          DedaddidEquals: null,
        },
        printUrl: null,
        title: null,
        anzhiOptipns: [],
        tongjiOptions: [],
      };
    },
    methods: {
      exportExcel() {
        var header
        var startTime
        if (this.selectData.ArgdateGreaterAndEquals) {
          startTime = this.selectData.ArgdateGreaterAndEquals.toLocaleDateString();
        } else {
          startTime = '空';
        }

        if (this.selectData.ArgdateLessAndEquals != null) {
          var endTime = this.selectData.ArgdateLessAndEquals.toLocaleDateString();
          header = localStorage.getItem('orgname') + '生态奖补查询' + '(' + startTime + '--' + endTime + ')';
        } else {
          header = localStorage.getItem('orgname') + '生态奖补查询' + '(' + startTime + '--' + '空' + ')';
        }
        if (this.dataList.length === 0) {
          this.$message.error("无导出数据！");
          return;
        }
        this.downloadLoading = true;

        require.ensure([], () => {
          const {
            export_json_to_excel
          } = require("@/vendor/Export2Excel");
          export_json_to_excel(this.headList, this.dataList, header);
          this.downloadLoading = false;
        });
      },
      //  功能操作
      operate(order) {
        this.order = order;
        switch (this.order) {
          //   case '导出Excel':
          case '导出':
            this.exportExcel()
            break;
          case '打印':
            this.$refs.printPdf.report(
              '打印生态奖补查询',
              this.getDataC()
            );
            break;
        }
      },

      //获取表头
      getCreColumn() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Column.GetEnvironAwardColumns,
          res => {
            this.headList = res.data.content;
          });
      },
      getaddress() {
        // 获取下拉选择
        apiBase.DoService({ARWECOLOGY: 1 }, apiBase.getApiAdress().JointPlace.GetPlacementAway, res => {
         this.anzhiOptipns= res.data.content;
        });
        apiBase.DoService({}, apiBase.getApiAdress().JointPlace.GetStatusAddress, res => {
         this.tongjiOptions= res.data.content;
        });
      },
      //获取查询数据
      getData() {
        this.dataList = [];
        let Data = JSON.parse(JSON.stringify(this.selectData));
        if (Data.ArgdateGreaterAndEquals)
          Data.ArgdateGreaterAndEquals = formatDate(Data.ArgdateGreaterAndEquals, "yyyyMMdd");
        if (Data.ArgdateLessAndEquals)
          Data.ArgdateLessAndEquals = formatDate(Data.ArgdateLessAndEquals, "yyyyMMdd");
        let data = {
          PageIndex: -1,
          PageSize: 0,
          OrderBy: this.pageOrder.orderType,
          OrderByType: this.pageOrder.orderSort,
          Data: Data
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Report.QueryEnvironAwardReport,
          res => {
            this.dataList = res.data.content.OutData;
          });
      },
      getDataC() { //打印
        let Data = JSON.parse(JSON.stringify(this.selectData));
        if (Data.ArgdateGreaterAndEquals)
          Data.ArgdateGreaterAndEquals = formatDate(Data.ArgdateGreaterAndEquals, "yyyyMMdd");
        if (Data.ArgdateLessAndEquals)
          Data.ArgdateLessAndEquals = formatDate(Data.ArgdateLessAndEquals, "yyyyMMdd");
        let data = {
          PageIndex: -1,
          PageSize: 100,
          OrderBy: this.pageOrder.orderType,
          OrderByType: this.pageOrder.orderSort,
          Data: Data
        };
        return data;
      },
      //重置查询
      btnRepeat() {
        this.selectData = {
          ArgdateGreaterAndEquals: null,
          ArgdateLessAndEquals: null,
          ArgwayEquals: null,
          DedaddidEquals: null,
        };
        this.selectData.ArgdateGreaterAndEquals = new Date();
        this.selectData.ArgdateGreaterAndEquals.setDate(1);
        this.selectData.ArgdateLessAndEquals = new Date();
        var day = new Date();
        var year = day.getFullYear();
        var month = day.getMonth() + 1;
        var d = new Date(year, month, 0);
        var dat = d.getDate();
        this.selectData.ArgdateLessAndEquals.setDate(dat);
        this.getData();
      },
      // 控制是否显示
      btnShow(val) {
        switch (val) {
          //   case '导出Excel':
          case '导出':
          case '打印':
            return true
            break;
        }
      },
    },
    components: {
      dataTable,
      sweetModal,
      printmodal
    },
    created() {
    this.selectData.ArgdateGreaterAndEquals = new Date();
    this.selectData.ArgdateGreaterAndEquals.setDate(1);
    this.selectData.ArgdateLessAndEquals = new Date();
    var day = new Date();
    var year = day.getFullYear();
    var month = day.getMonth() + 1;
    var d = new Date(year, month, 0);
    var dat = d.getDate();
    this.selectData.ArgdateLessAndEquals.setDate(dat);
      this.getaddress();
      this.getCreColumn();
      this.getData();
    }
  };

</script>
